import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import Layout from '@/layout'

export let constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',  //关闭窗口
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',  // 
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '页面一', icon: 'dashboard', affix: true }
      }
    ]
  }
]


let MaternalChildArr= [
  {
    path: '/projectManage',
    component: Layout,
    meta: { title: '项目管理', icon: 'icon', noCache: true },
    children: [
      {
        path: 'project',
        component: () => import(/* webpackChunkName: "project" */ '@/views/projectManage/project'),
        name: 'project',
        meta: { title: '项目信息'}
      },
     {
        path: 'billing',
        component: () => import(/* webpackChunkName: "billing" */ '@/views/projectManage/billing'),
        name: 'billing',
        meta: { title: '开票信息' }
      },
      {
        path: 'collection',
        component: () => import(/* webpackChunkName: "collection" */ '@/views/projectManage/collection'),
        name: 'collection',
        meta: { title: '收款信息' }
      },
      {
        path: 'expenses',
        component: () => import(/* webpackChunkName: "expenses" */ '@/views/projectManage/expenses'),
        name: 'expenses',
        meta: { title: '报销信息' }
      },
      {
        path: 'commission',
        component: () => import(/* webpackChunkName: "commission" */ '@/views/projectManage/commission'),
        name: 'commission',
        meta: { title: '提成信息' }
      }
    ]
  },
  {
    path: '/basicsManage',
    component: Layout,
    meta: { title: '基础信息', icon: 'icon', noCache: true },
    children: [
      {
        path: 'enterprise',
        component: () => import(/* webpackChunkName: "enterprise" */ '@/views/basicsManage/enterprise'),
        name: 'enterprise',
        meta: { title: '企业信息'}
      },
      {
        path: 'assessment',
        component: () => import(/* webpackChunkName: "assessment" */ '@/views/basicsManage/assessment'),
        name: 'assessment',
        meta: { title: '考核系数' }
      }
    ]
  },
  {
    path: '/statisticsManage',
    component: Layout,
    meta: { title: '统计报表', icon: 'icon', noCache: true },
    children: [
      {
        path: 'commissiontotal',
        component: () => import(/* webpackChunkName: "commissiontotal" */ '@/views/statisticsManage/commissiontotal'),
        name: 'commissiontotal',
        meta: { title: '提成统计汇总'}
      },
      {
        path: 'itemstotal',
        component: () => import(/* webpackChunkName: "itemstotal" */ '@/views/statisticsManage/itemstotal'),
        name: 'itemstotal',
        meta: { title: '提成统计项目' }
      },
      {
        path: 'personneltotal',
        component: () => import(/* webpackChunkName: "personneltotal" */ '@/views/statisticsManage/personneltotal'),
        name: 'personneltotal',
        meta: { title: '提成统计人员' }
      },
      {
        path: 'outputtotal',
        component: () => import(/* webpackChunkName: "outputtotal" */ '@/views/statisticsManage/outputtotal'),
        name: 'outputtotal',
        meta: { title: '单人项目产值汇总' }
      },
      {
        path: 'accountstotal',
        component: () => import(/* webpackChunkName: "accountstotal" */ '@/views/statisticsManage/accountstotal'),
        name: 'accountstotal',
        meta: { title: '应收账款汇总' }
      }
    ]
  },
  {
    path: '/systemManage',
    component: Layout,
    meta: { title: '系统管理', icon: 'icon', noCache: true },
    children: [
      {
        path: 'users',
        component: () => import(/* webpackChunkName: "users" */ '@/views/systemManage/users'),
        name: 'users',
        meta: { title: '用户管理'}
      },
      {
        path: 'role',
        component: () => import(/* webpackChunkName: "role" */ '@/views/systemManage/role'),
        name: 'role',
        meta: { title: '角色管理' }
      },
      {
        path: 'menu',
        component: () => import(/* webpackChunkName: "menu" */ '@/views/systemManage/menu'),
        name: 'menu',
        meta: { title: '菜单管理' }
      }
    ]
  },
]

constantRoutes= constantRoutes.concat(MaternalChildArr)

export const asyncRoutes = [  ];
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

// router.addRoutes(constantRoutes)
export default router
